package com.wzh.glsc.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author xiaoming
 * @PackageName:com.wzh.glsc.auth.config
 * @ClassName:@{NAME}
 * @Description:
 * @date:@{DATE}@{TIME}
 */
//配置redis中存储的session格式及信息
@Configuration
public class GlscSessionConfig {

    //实现RedisSerializer接口并放入容器中
    //这里指定的是fastjson的方式序列化数据
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }

    //设置session的作用域、名称等信息 并放入容器中
    @Bean
    public CookieSerializer cookieSerializer(){
        //这里的DefaultCookieSerializer 是实现了CookieSerializer接口的
        DefaultCookieSerializer cookieSerializer=new DefaultCookieSerializer();
        //放大session的作用域 实现子域名共享session   这里设置的是总域名
        cookieSerializer.setDomainName("gulimall.com");
        cookieSerializer.setCookieName("GULIMALL.COM");
        return cookieSerializer;
    }

}
